//
//  OperatorApplyController.swift
//  rxCoreLogic
//
//  Created by yq on 2021/1/26.
//

import UIKit
import SnapKit

enum RxSwiftDemoType {
	case 用户名密码校验官方版
	case 注册登录
	case 加载指示器的使用
	
	var raw: String {
		return String(describing: self)
	}
	 
}

class OperatorApplyController: YViewController {
	
	var rxSwiftDemoLsit: [RxSwiftDemoType] = [.用户名密码校验官方版, .注册登录, .加载指示器的使用]
	
	lazy var tableView: UITableView = {
		let tableView = UITableView()
		tableView.delegate = self
		tableView.dataSource = self
		tableView.tableFooterView = UIView()
		tableView.estimatedRowHeight = 45
		tableView.rowHeight = UITableView.automaticDimension
		tableView.register(UITableViewCell.self, forCellReuseIdentifier: String(describing: UITableViewCell.self))
		return tableView
	}()
	
    override func viewDidLoad() {
        super.viewDidLoad()

		view.backgroundColor = .white
		self.navigationItem.title = "应用"
		
		view.addSubview(tableView)
		tableView.snp.makeConstraints { (make) in
			make.edges.equalToSuperview()
		}
	}
}

//MARK: - ✨== Delegate / DataSource ==✨
extension OperatorApplyController: UITableViewDelegate, UITableViewDataSource {

	func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
		return rxSwiftDemoLsit.count
	}
	
	func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
		let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: UITableViewCell.self ))
		cell?.textLabel?.text = rxSwiftDemoLsit[indexPath.row].raw
		return cell!
	}
	
	func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
		tableView.deselectRow(at: indexPath, animated: true)

		let demoType = rxSwiftDemoLsit[indexPath.row]
		switch demoType {
			case .用户名密码校验官方版:
				let userValid = YLoginViewController()
				userValid.title = demoType.raw
				self.navigationController?.pushViewController(userValid, animated: true)
			case .注册登录:
				let registeVc = RegisterViewController()
				registeVc.title = demoType.raw
				self.navigationController?.pushViewController(registeVc, animated: true)
			case .加载指示器的使用:
				let activityVc = ActivityViewController()
				activityVc.title = demoType.raw
				self.navigationController?.pushViewController(activityVc, animated: true)
		}
	}
	
}
